package com.cgtong.android.adapter;

import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
import android.widget.TextView;

import com.cgtong.android.R;
import com.cgtong.android.bean.MonthYearReportBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by chunc on 2017/10/21.
 */

public class ProblemCountMonthYearAdapter extends BaseQuickAdapter<MonthYearReportBean, BaseViewHolder> {

    private boolean isMonthReport;//true;月报 false:年报

    public void setMonthReport(boolean monthReport) {
        isMonthReport = monthReport;
    }

    public ProblemCountMonthYearAdapter(@Nullable List<MonthYearReportBean> data) {
        super(R.layout.adapter_problem_count_monthly, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, MonthYearReportBean item) {

        helper.setText(R.id.total_num_txt, item.getTotalNum() + "");
        helper.setText(R.id.satisfied_txt, item.getGoodLevelNum() + "");
        TextView satisfiedTxt = helper.getView(R.id.satisfied_txt);
        String str = format(mContext.getString(R.string.txt_good_prefix), item.getGoodLevel())
                + format(mContext.getString(R.string.txt_fine_prefix), item.getFineLevel())
                + format(mContext.getString(R.string.txt_normal_prefix), item.getNormalLevel());
        Spanned spanned = Html.fromHtml(str);
        satisfiedTxt.setText(spanned);

        TextView unsatisfiedTxt = helper.getView(R.id.unsatisfied_txt);
        String str1 = format(mContext.getString(R.string.txt_bad_prefix),item.getBadLevel());
        Spanned spanned1 = Html.fromHtml(str1);
        unsatisfiedTxt.setText(spanned1);


        helper.setText(R.id.time_limit_txt, item.getExpiredNum() + "");
        helper.setText(R.id.date_txt, item.getDatetime());

        if (isMonthReport) {
            helper.setGone(R.id.expired_percent_txt, false);
        } else {
            helper.setGone(R.id.expired_percent_txt, true);
            TextView expiredTxt = helper.getView(R.id.expired_percent_txt);
            String str2 = format(mContext.getString(R.string.txt_expired_prefix),item.getExpiredPer());
            expiredTxt.setText(Html.fromHtml(str2));

        }
    }


    private String format(String name, int content) {
        return name + "<font color=\"#54BB50\">" + content + "%</font>";
    }
}
